package com.foreveross.crawl.counter;

import java.util.Date;




/**
 * 抓取引擎计数器
 * @author keman
 *
 */
public class Counter {

	
	public Counter(String name){
		counterName=name;
	}
	
	
	/**
	 * 计数器名字
	 */
	private String counterName="";
	
	/**
	 * 创建时间
	 */
	private Date createDate = new Date();
	
	/**
	 * 最后计数时间
	 */
	private Date lastCountDate = new Date();
	
	/**
	 * 计数器值
	 */
	private long count=0;

	public String getCounterName() {
		return counterName;
	}

	public void setCounterName(String counterName) {
		this.counterName = counterName;
	}

	public Date getCreateDate() {
		return createDate;
	}

	public Date getLastCountDate() {
		return lastCountDate;
	}

	/**
	 * 获取计数
	 * @return
	 */
	public long getCount() {
		return count;
	}

	/**
	 * 计数
	 */
	public synchronized void count() {
		this.count = count+1;
		this.lastCountDate = new Date();
	}
	
	/**
	 * 计数
	 */
	public synchronized void countNum(int num) {
		this.count = count+num;
	}
	
	/**
	 * 重置计数器
	 * @return
	 */
	public boolean resetCounter(){
		boolean succeed=false;
		
		this.count=0;
		//重置后，计数时间为当前时间
		this.createDate  = new Date();
		this.lastCountDate = new Date();
		return succeed;
	}
	
}
